/** @file    EncodersXmlQt_Security.cpp
 *  @author  Alessandro Polo
 *  @version $Id: EncodersXmlQt_Security.cpp 2657 2010-06-15 19:57:29Z alex $
 *  @brief
 * The header for this class can be found in EncodersXmlQt_Security.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/persistence/qt/EncodersXmlQt_Security.h>

 #include <framework/persistence/qt/EncodersXmlQt_Core.h>
 #include <core/ObjectAllocator.h>


namespace wosh {
 namespace persistence {
  namespace qt {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Security_SecurityToken3rdParty, "wosh::security::SecurityToken3rdparty", 0.0, _static_EncoderXml_Qt_Security_SecurityToken3rdParty )

WRESULT EncoderXml_Qt_Security_SecurityToken3rdParty::serializeTo( const wosh::security::SecurityToken3rdparty* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::serializeTo(object, doc, contNode, true );
	EncoderBaseXmlQt::serializeString( "user-id", object->getUserId(), doc, contNode, encoder_options );
	QDomElement authorityNode = doc.createElement("authority"); contNode.appendChild(authorityNode);
	EncoderBaseXmlQt::serializeString( "name", object->getAuthorityName(), doc, authorityNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "channel", object->getAuthorityChannel(), doc, authorityNode, encoder_options );
	return ret;
 }

WRESULT EncoderXml_Qt_Security_SecurityToken3rdParty::deserializeFrom( wosh::security::SecurityToken3rdparty* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::deserializeFrom(object, contNode );
	object->user_contact_id = EncoderBaseXmlQt::deserializeString( "user-id", "", contNode );
	QDomElement authorityNode = contNode.namedItem("authority").toElement();
	if ( !authorityNode.isNull() ) {
		object->data.authority_name = EncoderBaseXmlQt::deserializeString( "name", "", authorityNode );
		object->data.type = EncoderBaseXmlQt::deserializeLong( "channel", wosh::security::CHANNEL_UNKNOWN, authorityNode );
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Security_SecurityTokenOS, "wosh::security::SecurityTokenOS", 0.0, _static_EncoderXml_Qt_Security_SecurityTokenOS )

WRESULT EncoderXml_Qt_Security_SecurityTokenOS::serializeTo( const wosh::security::SecurityTokenOS* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::serializeTo(object, doc, contNode, true );
	EncoderBaseXmlQt::serializeString( "user-id", object->getOsUsername(), doc, contNode, encoder_options );
	QDomElement osNode = doc.createElement("os-info"); contNode.appendChild(osNode);
	EncoderBaseXmlQt::serializeString( "hostname", object->getOsHostName(), doc, osNode, encoder_options );
	EncoderBaseXmlQt::serializeString( "name", object->getOsName(), doc, osNode, encoder_options );
	EncoderBaseXmlQt::serializeLong( "login-type", object->getLoginType(), doc, osNode, encoder_options );
	return ret;
 }

WRESULT EncoderXml_Qt_Security_SecurityTokenOS::deserializeFrom( wosh::security::SecurityTokenOS* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::deserializeFrom(object, contNode );
	object->os_username = EncoderBaseXmlQt::deserializeString( "user-os", "", contNode );
	QDomElement osNode = contNode.namedItem("os-info").toElement();
	if ( !osNode.isNull() ) {
		object->data.os_hostname = EncoderBaseXmlQt::deserializeString( "name", "", osNode );
		object->data.os_name = EncoderBaseXmlQt::deserializeString( "channel", "", osNode );
		object->data.type = EncoderBaseXmlQt::deserializeLong( "login-type", wosh::security::LOGIN_UNKNOWN, osNode );
	 }
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_ENCODER_XML_Qt_BIND(wosh::persistence::qt::EncoderXml_Qt_Security_SecurityTokenShell, "wosh::security::SecurityTokenShell", 0.0, _static_EncoderXml_Qt_Security_SecurityTokenShell )

WRESULT EncoderXml_Qt_Security_SecurityTokenShell::serializeTo( const wosh::security::SecurityTokenShell* object, QDomDocument& doc, QDomElement& contNode, int encoder_options ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::serializeTo(object, doc, contNode, encoder_options );
	return ret;
 }

WRESULT EncoderXml_Qt_Security_SecurityTokenShell::deserializeFrom( wosh::security::SecurityTokenShell* object, const QDomElement& contNode ) {
	if ( object == NULL ) return WRET_ERR_PARAM;
	WRESULT ret = EncoderXml_Qt_SecurityToken::deserializeFrom(object, contNode );
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

  }; // namespace qt
 }; // namespace persistence
}; // namespace wosh
